package com.example.stock.service.impl;

import com.example.stock.excel.DailyMonitor;
import com.example.stock.service.DailyMonitorService;
import com.example.stock.util.DataUtil;
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class DailyMonitorServiceImpl implements DailyMonitorService {

    private List<DailyMonitor> getDailyMonitorList() {
        return DataUtil.getDailyMonitorData();
    }

    @PostConstruct
    private void init() {
        dailyMonitorMap = getDailyMonitorList().stream().collect(Collectors.groupingBy(DailyMonitor::getMonitorDate));
    }

    private Map<String, List<DailyMonitor>> dailyMonitorMap;

    @Override
    public Map<String, List<DailyMonitor>> getDailyMonitorMap() {
        return dailyMonitorMap;
    }

    @Override
    public List<DailyMonitor> getDataByMonitorDate(String monitorDate) {
        return getDailyMonitorMap().get(monitorDate);
    }
}